<?php 
	include (dirname(__FILE__)."/../include/header.php"); 
	include (dirname(__FILE__)."/../include/zy_function3.php"); 
?>
<style>
.black_overlay{
	display: none;
	position: absolute;
	top: 0%;
	left: 0%;
	width: 0%;
	height: 0%;
	z-index:1001;
	-moz-opacity: 0.8;
	opacity:.80;
	filter: alpha(opacity=80);
}
#reply { width:370px; height:65px; max-height:65px; max-width:370px; }
.white_content {
	display: none;
	position: fixed;
	top: 30%;
	left: 50%;
	margin-left:-200px;
	width: 380px;
	padding:10px;
	height: 180px;
	border: 3px solid lightblue;
	background-color: white;
	z-index:1002;
	overflow: auto;
	box-shadow: 0px 1px 5px 0px #4a4a4a;
-webkit-box-shadow: 0px 1px 5px 0px #4a4a4a;
-moz-box-shadow: 0px 1px 5px 0px #4a4a4a;
}
.white_content_small {
	display: none;
	position: absolute;
	top: 20%;
	left: 30%;
	width: 40%;
	height: 50%;
	border: 16px solid lightblue;
	background-color: white;
	z-index:1002;
	overflow: auto;
}
</style>
 <style type="text/css">
<!--
a:link {
 text-decoration: none;
}
a:visited {
 text-decoration: none;
}
a:hover {
 text-decoration: none;
}
a:active {
 text-decoration: none;
}
-->
</style>
<?php
	$shop_id=$_REQUEST['shop_id'];
	$sq=mysql_query("select * from zy_shop where shop_id='".$shop_id."'");
	$shop=mysql_fetch_array($sq);
?>
<?php
//添加留言
	$shop_id=$_REQUEST['shop_id'];
	if(!empty($_POST['submit'])){			
		$message=$_POST['message'];
		if($message!=""){
			$sql2 = "insert into zy_message(user_id,shop_id,message,reply_id,remark,is_delete,create_user,create_time,update_user,update_time) values('".$_SESSION['_user']['user_id']."','$shop_id','$message',0,'qq',0,'ww',now(),'ww',now())";
			mysql_query($sql2);
			//   header("location:shop_message.php?shop_id=".$shop_id);		
			}else{
			$error="留言不能为空";
		}	
	}
	//添加回复
	if(!empty($_POST['submit1'])){
		$reply=$_POST['reply'];
		$rep_id=$_POST['rep_id'];
		if($reply!=""){
			$sql3 = "insert into zy_message(user_id,shop_id,message,reply_id,remark,is_delete,create_user,create_time,update_user,update_time) values('".$_SESSION['_shop']['user_id']."','$shop_id','$reply','$rep_id','qq',0,'ww',now(),'ww',now())";
			mysql_query($sql3);
			// echo $sql3;
	//		header("location:shop_message.php?shop_id=".$shop_id);	
		}else{
		$error="回复不能为空";
		}	
	}
	//组织生成分页
	$sql="select count(message_id) num from zy_message where reply_id=0 and shop_id='".$shop_id."' ".$where;
	//当前页
	$p=$_REQUEST['p'];
	if(!$p>0){
		$p=1;
	}
	//每页记录条数
	$pagesize=10;
	$Page=page($p,$sql,'','',$pagesize);
	mysql_query($sql);
	$sql1="select * from zy_message where reply_id=0 and shop_id='".$shop_id."'".$where."order by update_time desc limit ".($p-1)*$pagesize.",".$pagesize;
	$result=mysql_query($sql1);
	$n=1;
?>
  <div class="container">
    <ul class="breadcrumb">
   			<?php 
  	$shop_id=$_GET['shop_id'];
   $sql2="select * from zy_shop where shop_id='".$shop_id."'";
  	 // echo $sql2;
  	$query2=mysql_query($sql2);
  	if($query2=mysql_fetch_array($query2)){
  	?>
  	 <?php 
  		$sql="SELECT a.id id1,a.name name1,b.id id2 ,b.name name2,c.`id` id3 ,c.`name` name3 FROM zy_businessarea a LEFT JOIN zy_businessarea b ON a.`id`=b.`parentId` LEFT JOIN zy_businessarea c ON b.`id`=c.`parentId` WHERE c.`id`=".$query2['district']."";
  		//echo $sql;
  		$query4=mysql_query($sql);
  		if($query4=mysql_fetch_array($query4)){?>
  			<li><a href="<?php echo SITE_ROOT ?>/index.php"><?php echo $query4['name1'] ?></a>><a href="<?php echo SITE_ROOT ?>/index.php?id1=<?php echo $query4['id2'];?>"><?php echo $query4['name2'] ?></a>><a href="<?php echo SITE_ROOT ?>/index.php?id2=<?php echo $query4['id3'];?>"><?php echo $query4['name3']?></a>><?php echo $query2['shop_name'];?></li>
     <?php } }?>
    </ul>
    <div class="row">
      <div class="span12 right-fold bordered-box">
        <div class="row">
          <div class="span12">
            <div class="important-info alert warning"><?php echo $shop['introduction'];?> </div>
          </div>
          <div class="span9 master-side restaurant-content">
            <div class="row">
              <div class="span9">
              <ul class="nav nav-tabs restaurant-tab">
                <li ><a href="<?php echo SITE_ROOT?>/index_shop.php?shop_id=<?php echo $shop_id;?>">菜单</a></li>
                <li><a href="<?php echo SITE_ROOT?>/shop/shop_evaluate.php?shop_id=<?php echo $shop_id;?>">评价</a></li>
                <li class="active"><a href="<?php echo SITE_ROOT?>/shop/shop_message.php?shop_id=<?php echo $shop_id;?>">留言</a></li>
              </ul>
			  			<div class="restaurant-tab-content">
			<div class="comments">
		<ul>
<?php 
	while($mes=mysql_fetch_array($result)){
?>
		<li>
		<div class="comment">
		<div class="content">
		<p><?php echo $mes['message'];?></p>
		</div>
		<div class="sig"> <span class="user"><?php $query="select * from zy_message where message = '".$mes['message']."' and create_time ='".$mes['create_time']."'"; 
		$rs=mysql_query($query);
		while($zy_message=mysql_fetch_array($rs)){
		$query_2="select * from zy_user where user_id ='".$zy_message['user_id']."'";
		$rs_2=mysql_query($query_2);
		while($zy_user=mysql_fetch_array($rs_2)){
 			echo $zy_user['username'];
		}
		}
		?></span> <span class="created-at zyCreated-at"><?php echo $mes['create_time'];?></span>
		<?php	
			$sql5=mysql_query("select * from zy_message where reply_id='".$mes['message_id']."'");
			if($rep=mysql_fetch_array($sql5)){
		?>
		<div class="reply">
		<div class="content">
		<p><?php echo $rep['message'];?></p>
		</div>
		<div class="sig"> <span class="user">餐厅回复</span> <span class="created-at"><?php echo $rep['create_time'];?></span> </div>
		</div>
		<?php }else{?>
		<?php if(isset($_SESSION['_shop'])){	?>
		<div class="reply" style="margin-right:10px;">
		<div class="content">
		<?php 
		
		//echo $_SESSION['_shop']['shop_id'];
		
		// echo $_GET['shop_id'];
		if( $_SESSION['_shop']['shop_id']==$_GET['shop_id']){
			?>
		<input type="submit" onClick="ShowDiv('MyDiv','fade','<?php echo $mes['message_id'];?>')" value="留言回复" style="margin-left:10px;"></div>
		<?php } ?>
		</div>
		<?php } }?>
		</div>
		</div>
		</li>
		<?php }?>
		</ul>
		<div class="pagination">
		<ul>
		<li>
		<?php if($Page['currentPage']>1){?>
      <?php if($Page['currentPage']!=1){?>
       <a href="<?php echo SITE_ROOT?>/shop/shop_message.php?shop_id=<?php echo $shop_id;?>">首页</a> 
	   <a href="<?php echo SITE_ROOT?>/shop/shop_message.php?shop_id=<?php echo $shop_id;?>&p=<?php echo $Page['currentPage']-1;?>&p=<?php echo $Page['currentPage']-1;?>">上一页</a>
       <?php } for ($i=$Page['begin'];$i<=$Page['end'];$i++){?>
       <a href="<?php echo SITE_ROOT?>/shop/shop_message.php?shop_id=<?php echo $shop_id;?>&p=<?php echo $i;?>;" <?php echo $i==$Page['currentPage'] ? "style='text-decoration: underline;font-weight: bold;'":''?> ><?php echo $i;?></a>
       <?php }if($Page['currentPage']!= $Page['totalPages']){?>
       <a href="<?php echo SITE_ROOT?>/shop/shop_message.php?shop_id=<?php echo $shop_id;?>&p=<?php echo $Page['currentPage']+1;?>;">下一页</a> 
	   <a href="<?php echo SITE_ROOT?>/shop/shop_message.php?shop_id=<?php echo $shop_id;?>&p=<?php echo $Page['totalPages'];?>">尾页</a></td>
        <?php }	}?>	
       <span> <?php if(!isset($_SESSION['_user'])){?>想给餐厅提意见 ? <a class="zyShopMessage" href="<?php echo SITE_ROOT?>/user_registration.php">注册</a>/<a class="zyShopMessage" href="<?php echo SITE_ROOT?>/user_login.php">登录</a><?php }?></span>
		</li>
		</ul>
</div>
<?php
	if(isset($_SESSION['_user'])){
?>
<form class="new-comment-form" action="shop_message.php?shop_id=<?php echo $shop_id;?>" method="POST">
	<div class="field_line" ><font color="red"><?php echo $error;?></font></div>
	<input type="hidden" name="restaurant_comment[id]" id="restaurant_comment_id" />
	<fieldset>
	<div class="clearfix">
	<label for="content">留言:</label>
	<div class="input">
	<input type="hidden" name="restaurant_comment[restaurant_id]" id="restaurant_comment_restaurant_id" value="59" />
	<textarea class="xxlarge" name="message" id="textarea" rows="3"></textarea>
	</div>
	</div>
	<div class="actions">
	<input type="submit" class="btn yellow" name="submit" value="发表留言" />
	</div>
	</fieldset>
</form>
<?php }?>
              </div></div></div>
            </div>
          </div>
          <?php include (dirname(__FILE__)."/../include/index_shop_right.php"); ?>
    </div></div>
<?php include (dirname(__FILE__)."/../include/footer.php"); ?>
<div id="MyDiv" class="white_content">
<div style="text-align: right; cursor: default; height: 40px;"> <span style="font-size: 14px; color:#666; cursor:pointer;" onClick="CloseDiv('MyDiv','fade')">关闭</span> </div>
<form name="form1" method="post" action="">
	<input type="hidden" name="rep_id" value="" id="rep_id"/>
	<textarea name="reply" cols="50" rows="10" id="reply"></textarea><br>
	<input name="submit1" type="submit" id="huifu" value="回复" class="btn-yellow" />
</form>
</div>
<script type="text/javascript">
//弹出隐藏层
function ShowDiv(show_div,bg_div,mes_id){
	document.getElementById(show_div).style.display='block';
	$("#rep_id").attr("value",mes_id);
}
//关闭弹出层
function CloseDiv(show_div,bg_div){
	document.getElementById(show_div).style.display='none';
}
</script>
</body></html>
<script type="text/javascript">
//弹出隐藏层
function ShowDiv(show_div,bg_div,mes_id){
	document.getElementById(show_div).style.display='block';
	$("#rep_id").attr("value",mes_id);
}
//关闭弹出层
function CloseDiv(show_div,bg_div){
	document.getElementById(show_div).style.display='none';
}
</script>
